package rickyGame.game.action
{
	import ricky.utils.FrameManager;
	import ricky.Interface.IAct;
	import ricky.game.action.Act2D;

	/**
	 * 行动助手
	 */
	public class ActionHelper implements IAct
	{
		/**
		 * 行动助手唯一实例
		 */
		public static function get inst():ActionHelper
		{
			if(!_inst)
				_inst=new ActionHelper();
			return _inst;
		}
		
		private static var _inst:ActionHelper;
		
		public function ActionHelper()
		{
			_acts=new Array();
			FrameManager.inst.addLogic(this);
		}
		
		/**
		 * 添加行动
		 */
		public function addAct(act:Act2D):void
		{
			var i:int=_acts.indexOf(act);
			if(i==-1)
			{
				_acts.push(act);
				act.completeFun=completeFun;
				act.begin();
			}
		}
		
		public function completeFun(e:Act2D):void
		{
			removeAct(e);
		}
		
		/**
		 * 删除行动
		 */
		public function removeAct(act:Act2D):void
		{
			var i:int=_acts.indexOf(act);
			if(i>=0)
				_acts.splice(i,1);
			
			act.end();
//			act.dispose();
		}
		
		/**
		 * 行动中
		 * @param timeline 当前时间戳
		 */
		public function action(timeline:Number):void
		{
			for each(var act:Act2D in _acts)
			{
				act.action(timeline);
			}
			
//			JDebug.trace("无主角的行动:"+_acts.length);
		}

		//*********************************************
		private var _acts:Array;//并行的所有行动
		
	}
}